package sg.edu.ntu.metaweb.storage.data;


import java.util.Date;

public class Link extends Contribution {

	public final static byte LINK_DIRECTION___OUTGOING = 1;
	public final static byte LINK_DIRECTION___INCOMING = 2;
	
	private String url;
	private byte type;
	private Date timestamp;
	
	public Link(User creator, String url, byte type) {
		super(creator);
		this.url = url;
		this.type = type;
		this.timestamp = new Date();
	}

	
	@Override 
	public boolean equals(Object obj) {
		
		if (obj == null) 
			return false;
		
		if (obj.getClass() != this.getClass()) 
			return false;
		
		Link l = (Link)obj;
		if ((this.url == l.url) && (this.contributor == l.contributor) && (this.type == l.type))
			return true;
		
		return false;		
	}
	
	@Override public int hashCode() {
        
		String string = this.contributor.geteMailAddress() + this.url + this.type;

        byte[] byteValue = string.getBytes();
        int hash = 0;
        int len = byteValue.length;
        for (int i = 0 ; i < len; i++) {
        	hash <<= 1;
        	if ( hash < 0 ) hash |= 1;
        	hash ^= byteValue[ i ];
        }
        return hash;
    }

}
